<?php 
/**
 * We did NOT put too much function in index controller for security reason 
 * 
 * @author Norman
 *
 */
class IndexController extends Zend_Controller_Action
{
	

	
    public function init(){

    }

    /**
     * this will only show logo nothing else
     */
    public function indexAction(){

	}
	/**
	 * this function is add by leo 
	 */
	public function controlPanelAction(){
		
		$show = $this->_getParam("show");
		$menu = new Model_DbTable_Menu();
		
		if($show == "fullmenu"){
			$mList = $menu->listAll();
			$this->view->mList = $mList;
		}

	}
	
	/**
	 * this function is no longer in use 
	 * this function was use to get the sales on ebay then send the promotion email
	 * accordingly
	 */
	
	public function sendpromotionemailAction(){
		/*
		$emailAccount = "promotion@lovebargain.com.au";
		$passWord = "mon80ash";
		$newEmail = new Model_Emailshandler();
		$resultMessage = $newEmail->downloadSold($emailAccount,$passWord);
		$emailFileName = $newEmail->analySubject($resultMessage[0]);
		$buyerArr = $newEmail->analyEmail($resultMessage[1]);
		
		echo "The Subject is:".$resultMessage[0]."<br />";
		echo "We find the Buyer is:".$buyerArr['buyerName']." Email is:".$buyerArr['buyerEmail']."<br />";
		echo "we Will use :".$emailFileName."<br />";
		echo "------------------------<br />";
		
		*/
		//$newEmail->sendPromotions($buyerArr['buyerName'],$buyerArr['buyerEmail'],$emailFileName);
		//echo "0000000000000000000000000000000000000000000000<br />";
		//echo "<pre>";
		//var_dump($resultMessage);
		//echo "</pre>";
		}
		
	/**
	 * this function show server php info 
	 */	
	public function pinfoAction(){
		
		echo phpinfo();
	}	
	/**
	 * this function is use for internal only
	 * it transfer time in 2 directions 
	 * from int value to stand value
	 * or transfer time to int value
	 */
	public function transferTimeAction(){
		
		if($_POST){

			if($_POST['int_time']!=""){
				
				date_default_timezone_set('Australia/Melbourne');
				
				echo date('Y-m-d H:i:s',$_POST['int_time'] );
			}
			else{
				
				echo Model_DatetimeHelper::tranferToInt($_POST['time']);
			}
			
			if(isset($_POST['code'])){
				echo base64_encode(trim($_POST['code']));
			}
		}
	}
		
	// this function is for us to test something 
	public function test2Action(){
		$this->_helper->layout->disableLayout();
		
		$file = fopen('D20150220135651.csv', 'r');
		$new = array();
		while (($line = fgetcsv($file)) !== FALSE) {
			$new[] = $line;
		}
		fclose($file);
		// start generate and let user download file
		$xlsTbl = '';
		foreach($new as $key => $val){
			$xlsTbl .= "<tr>";
			foreach($val as $kewLevelTwo => $valueLevelTwo){
				$xlsTbl .= "<td>" . $valueLevelTwo . "</td>";
			}
			$xlsTbl .= "</tr>";
		}
		header("Content-Type: application/vnd.ms-excel");
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("content-disposition: attachment;filename=excel-generated-" . date('Y-m-d-h-i') . ".xls");
		
		echo "<table border='1'>$xlsTbl</table>";
		
	}
	
	/**
	 * this function is for company info page try to connect the server
	 * if shake hands success then the company info page load the page 
	 * if the server is NOT available , it goes to emergeny login which is on our website
	 */
	public function shakehandAction(){
		
	$this->_helper->layout->disableLayout();
	echo 'shake({"ABC":"DEF"});';
	}	
	
	/**
	 * this function is add by leo, this is once off function 
	 */
	public function fixBonusAction(){
		$stfBonus = new Model_Payroll_Staffbonus();
		
		$bonusList = $stfBonus->onceCode();
		foreach ($bonusList as $k => $v){
			$amtTotal = $v['amt_total_bonus'];
			$amtBank = round($amtTotal/1.095,2);
			$amtSuper = $amtTotal-$amtBank;
			$stfBonus->updateAmt($v['id_bonus'], $amtBank, $amtSuper);
		}
		
		$result = $stfBonus->onceCode();
		foreach($bonusList as $k2 => $v2){
			echo $v2['id_bonus']." Total:".$v2['amt_total_bonus']." Bank:".$v2['amt_bank_bonus']." Super:".$v2['amt_bonus_super']."<br/>";
		}
	}
	// this is only function for us to test 
	public function testAction(){
		

		
		//echo Model_System_Downloadhelper::downloadUrl('http://110.143.46.117:1180/products/get-old-apos-product-description/barcode/APIPADLC102-3');

		/*$invoice = new Model_Offlineapos_Bsic_Invoice(Zend_Registry::get('db_bsic_off_apos'));
		$invPro = new Model_Offlineapos_Bsic_Invoicepro(Zend_Registry::get('db_bsic_off_apos'));
		$stock =  new Model_Offlineapos_Bsic_Balance(Zend_Registry::get('db_bsic_off_apos'));
		
		$invList = $invoice->getInvoicesByDate('2015-01-23');
		d($invList);
		
	
		$a = 2.34454334436346;
		echo round($a,2);
			*/
		/*
		foreach($invList as $invLine){
			
			$invNo = trim($invLine['INV_NO']);
			$details = $invPro->getInvoiceProducts($invNo);
			d($details);
		}
		*/
		//$stock->updateStockBalance("SPCRAPIPADA", "PMIC",8);
		//$stockLine = $stock->getStockBalance("SPCRAPIPADA", "PMIC");
		
		//d($stockLine);
		
		//mail("dqq_jz@msn.com","xxx","xxx",$headers);
		/*
		$shop = 'WBIC';
		$inv = Model_Aposinit::initAposInvoice($shop);
	
		$invPro = Model_Aposinit::initAposInvPro($shop); 
		
		$invDis = $inv->ifInvoiceDiscount('L150106003');
		$itemDis = $invPro->ifInvoiceDiscount('L150106003');
		
		d($invDis,$itemDis);
		*/
		//echo $invHead = substr(Model_DatetimeHelper::dateToday(),2,2);
		
		//$psStatus = new Model_Ps_Orderstatusupdate();
		//$idOrder = 608;
		//$idStatus = 6;
		//Model_Ps_Orderstatusupdate::updateStatus($idOrder, $idStatus);
		//Model_Ps_Orderstatusupdate::updateStatusHistory($idOrder, $idStatus);
		
		//$att = new Model_DbTable_Psattribute(Zend_Registry::get('db_remote'));
		//$row = $att->getPsattribute(15);
		//d($row);
		
		//$mail = new Model_Emailshandler();
		//$mail->sendNormalEmail("dqq_jz@msn.com;eco1@phonecollection.com.au","tttt","");
		
		/*
		$po = new Model_DbTable_Order_Weeklyorder();
		
		$pList = $po->listAll();
		
		foreach($pList as $r){
			if($r['id_order']> 31900 && strlen(trim($r['des_product'])) <3 && trim($r['code_product'])!="" ) {
				
				$des =file_get_contents('http://192.168.1.126/products/get-old-apos-product-description/barcode/'.strtoupper(trim($r['code_product'])));
				
				$po->updateDes($r['id_order'], $des);
				
				
			}
			
		}
		
		
		
		$pro = new Model_Products_Detail();
		$proLine = $pro->getDetail(5950);
		d($proLine);
		
		
		
		if($_POST){

			d($_FILES);
			if(move_uploaded_file($_FILES['upload']['tmp_name'], getcwd()."/".$_FILES['upload']['name'])){
				
				echo exec('zbarimg '.getcwd()."/".$_FILES['upload']['name']);
			}
			
			
		}
		
		echo $_COOKIE["UserCookie"];
		
		echo Model_EncryptHelper::convertTo36(100);
		echo Model_EncryptHelper::convertTo36(1000);
		

		
		echo Model_DbTable_Pr_Loan::buildBorrowCode(20, 16, 367,2014011509456);
		
		echo date("Y-m-d H:i:s",1358200803
		);
		//dec2hex()
		
		
		
		$time_start = microtime(true);
		
		$invPro = new Model_DbTable_Apos_Invoice_Products_Bb(Zend_Registry::get('db_oldapos'));
		$stockbal = new Model_DbTable_Apos_Stock_Balanceold(Zend_Registry::get('db_oldapos'));
		
		
//		echo $invPro->isHotItem('CHACCMUSB2IN1');
		$dateTwoWeekBegin = Model_DatetimeHelper::adjustWeeks("sub",Model_DatetimeHelper::getLastWeekMonday(),1);
		$dateTwoWeekEnd = Model_DatetimeHelper::adjustWeeks("sub",Model_DatetimeHelper::getLastWeekSunday(),1);
		

		$stock = new Model_DbTable_Apos_Stock_Productdes(Zend_Registry::get('db_oldapos'));
		$sList = $stock->getAll();
		
		//var_dump($sList);
		$cot = 0;
		$okCot = 0;
		
		foreach($sList as $key => $v){
			set_time_limit(0);
			
			$barCode = trim($v['SCODE']);
			
			if(substr($v['SCODE'],0,4)!="STA-" && $cot < 4000 ){

					$sales = $invPro->getProductSalesQtyByDates(Model_DatetimeHelper::getLastWeekMonday(),Model_DatetimeHelper::getLastWeekSunday(),trim($v['SCODE']));
					$wk2sales =  $invPro->getProductSalesQtyByDates($dateTwoWeekBegin, $dateTwoWeekEnd,trim($v['SCODE']));
					//$maxSold =  $invPro->maxSoldWeeks($barCode,Model_DatetimeHelper::getLastWeekSunday(),4);
					
					$avgSales = ($sales + $wk2sales) /2;
					 
					$ifHot = $invPro->isHotItem($barCode);
					$pickup = 0;
					$onhands = $stockbal->getStockBalance($barCode,"BB");
					$onhand = $onhands['BALANCE'];
					if($ifHot == "HOT" ){
						$pickup = $onhand - ceil($avgSales*1.5) ;
					}
					if($ifHot == "NORMAL" ){
						$pickup = $onhand - floor($avgSales*1.5);
					}
					if($ifHot == "COLD" ){
						$pickup =  $onhand - ceil($avgSales);
					}
					
					$cot++;
					if($pickup > 0 ){
						
						echo $cot.",".$v['SCODE'].",".$v["DESCRIPT"].",".$onhand.",".$ifHot,",".$pickup."<br />";
						
					}
					else{
						
						//echo "OK";
						$okCot++;
					}
					
					
				
			}			
		}
		
		echo $okCot;
		
		*/
		/*
		$fl = fopen(".csv","r");
		$cot =0;
		echo "<br/><br/>";
		
		while(($lineData = fgetcsv($fl))!=false){
			
			//var_dump($lineData);
			if($cot >0){
				$barCode = trim($lineData[0]);
				
				$sales = $lineData[3];
				$wk2Sales = $invPro->getProductSalesQtyByDates($dateTwoWeekBegin, $dateTwoWeekEnd, $barCode);
				
				$sales = ($sales + $wk2Sales)/2;
				
				$max4Week = $invPro->maxSoldWeeks($barCode,Model_DatetimeHelper::getLastWeekSunday(),4);
				
				$onhand = $lineData[4];
				
				$wh = $lineData[5];
				$ifHot = $invPro->isHotItem($barCode);
				$pickup = 0;
				if($ifHot == "HOT" ){
					$pickup = ceil($sales*1.5) - $onhand;	
				}
				if($ifHot == "NORMAL" ){
					$pickup = floor($sales*1.5) - $onhand;
				}
				if($ifHot == "COLD" ){
					$pickup = ceil($sales - $onhand);
				}				
				if($pickup <0 ){
					$pickup =0;
				}
				$strPossible = "";
				
				
				if(($pickup + $onhand) < $max4Week){
					
					$strPossible = $max4Week;
				}
				
				echo $lineData[0].",".$lineData[1].",".$lineData[2].",".$lineData[3].",".$lineData[4].",".$lineData[5].",".$ifHot.",".$sales.",".$pickup.",".$strPossible."<br />";
				
			}
			$cot++;
			
		}
		
		*/
		//$time_end = microtime(true);
		
		//$time = $time_end - $time_start;
		
		//echo "Time:".$time;
		
		/*
		
		echo date("U", strtotime("23:59"));
		
		$arr = array("a","b","c"=> 3);
		echo serialize($arr);
		
		
		
		
		$cf = new Model_Cbfilehandler();
		$arrCFile = $cf->readFile('MRCHRPT20131020.csv');
		echo "<pre>";
		var_dump($arrCFile);
		echo "</pre>";
		$invOld = new Model_DbTable_Apos_Invoice_Bb(Zend_Registry::get('db_oldapos'));
		
		$arrInvoice = $invOld->getInvoicesByDate('2013-10-18 00:00:00');
		
		
		
		$arrAposInv = array();
		foreach($arrInvoice as $inv){
			if($inv["STATUS"] != "V" ){
					
				if(trim($inv["PTYPE1"])!=""){
					switch((int)$inv["PTYPE1"]){
						case(1):{
							break;
						}
						case(6):{
							break;
						}
						case(7):{
							break;
						}
						default:{
							$arrAposInv[] = $inv["INV_NO"];
							$arrAposInv[] = $inv["TIME"];
							$arrAposInv[] = round($inv["PAID1"],2);
							break;
						}
					};
		
				}
		
				if(trim($inv["PTYPE2"])!=""){
					
					switch((int)$inv["PTYPE2"]){
						case(1):{
				
							break;
						}
						case(6):{
				
							break;
						}
						case(7):{
							break;
						}
						default:{
							$arrAposInv[] = $inv["INV_NO"];
							$arrAposInv[] = $inv["TIME"];
							$arrAposInv[] = round($inv["PAID2"],2);
							break;
						}
					};
						
				}
					
				if(trim($inv["PTYPE3"])!=""){
					switch((int)$inv["PTYPE3"]){
						case(1):{
							
							break;
						}
						case(6):{
							
							break;
						}
						case(7):{
							break;
						}
						default:{
							$arrAposInv[] = $inv["INV_NO"];
							$arrAposInv[] = $inv["TIME"];
							$arrAposInv[] = round($inv["PAID3"],2);
							break;
						}
					};
						
				}

			}
			
		}
		
		
		//var_dump($arrAposInv);
		$arrMatch = array();
		
		foreach($arrCFile[1]['BBPC'] as $key => $v){
			$arrMatch[] = substr(trim($v[4]),0,5);
			$arrMatch[] = round($v[11],2);
		}
		
		echo "<pre>";
		var_dump($arrAposInv,$arrMatch);
		echo "</pre>";
		
		foreach($arrMatch as $key2 => $v2){
			if( $key2 %2 == 1){
				
				//$find = array_search($v2, $arrAposInv,true);
				
				$findKeys = array_keys($arrAposInv,$v2,true);
				
				if($findKeys!==false){
					//check time 
				foreach($findKeys as $find){	
					$intMatchTime = date("U",strtotime($arrMatch[ $key2 -1]));
					$intAposTime = date("U",strtotime($arrAposInv[ $find -1]));

					if(abs($intMatchTime - $intAposTime) < 121 ){
						$arrAposInv[$find] = null;
						$arrAposInv[$find - 1] = null;
						$arrAposInv[$find - 2] = null;
						
						$arrMatch[$key2] = null;
						$arrMatch[$key2 -1] = null;
					}
				}	
					
				}
			}
			
		}
		
		//$arrAposInv = array_filter($arrAposInv, 'strlen');
		//$arrMatch = array_filter($arrMatch, 'strlen');
		echo "<pre>";
		var_dump($arrAposInv,$arrMatch);
		echo "</pre>";		
		*/
		//$invPro = new Model_DbTable_Apos_Invoice_Products_Ep(Zend_Registry::get('db_oldapos'));
		
		
		//$res = Model_DbTable_Products_Sales::eightWeekNewProduct("2013-09-02","2013-10-27");
		//var_dump($res);
		
		//$tOld = new Model_DbTable_Apos_Stock_Ktdataold(Zend_Registry::get('db_oldapos'));
		//$tList = $tOld->thisWeekTransfer('LC990APIPH4-4');
		//var_dump($tList);
		//$mail = new Model_Emailshandler();
		
		//$mail->sendNormalEmail("eco1@phonecollection.com.au","test","test");
		//$mail->sendNormalEmail("jeffrey.zhang@phonecollection.com.au","test","test");
		//date_default_timezone_set('Australia/Melbourne');
		
		//$attn = new Model_DbTable_Roster_Attnrecord();
		//$status = $attn->createStatusOffDuty();
		//$time = date("U",strtotime('2013-09-09 17:30:00'));
		//$ip = '0.0.0.0';
		
		//$attn->addRecord($staffId, $time, $ip, $shopHead, $status);
		/*
		$arrAttn = array(
				'3' => 'BSPC',
				'16' => 'BSPC',
				'26' => 'BSPC',
				'107' => 'BSPC',
				'10' => 'BSPC',
				'9' => 'CBPC',
				'2' => 'FGIC',
				'150' => 'FGIC',
				'151' => 'SLIC',
				'20' => 'PMIC',
				'125' => 'PMPC',
				'36' => 'EPPC',
				'97' => 'EPPC',
				'6' => 'NLPC',
				'162' => 'WGIC',
				'140' => 'WGPC',
				'165' => 'KCPC',
				'115' =>'DCIC',
				'118' => 'CSIC',
				'4' => 'CSIC',
				'141' => 'BBPC',
				'130' => 'BHPC',
				'125' =>'WBIC',
				'98' =>'PMPC',
				'133' => 'HPIC'
				);
		
		$arrAttn = array(
				'16' => 'BSIC',
				'26' => 'BSIC',
				'107' => 'BSIC',
				'10' => 'BSXP'
		);
		
		*/
		
		
		//foreach($arrAttn as $id => $shop){
			
		//	$attn->addRecord($id, $time, $ip, Model_EncryptHelper::sslPassword($shop), $status);
			
		//}
		
		//$rPro = new Model_DbTable_Pr_Prproducts();
		//$rPro->getProductDes($productCode)
		
		//echo $this->arrTry[0];
		//echo Model_DatetimeHelper::adjustDays("sub",date("Y-m-d"),170);
		
		//$testEntity = new Model_DbTable_Test;
		
		//$line= $testEntity->findOneBy(array('name'=>'Zaphod Beeblebrox'));
		//var_dump($line);
		
		//$testEntity->setName('Zaphod Beeblebrox');
		//$this->_em->persist($testEntity);
		//$this->_em->flush();
		
		//echo phpinfo();
		//$date = "2013-08-01";
		
		//echo Model_EncryptHelper::sslPassword("guan lin");
		//echo Model_DatetimeHelper::adjustMonths("sub", $date,1);
		
		//$fh = new Model_Fileshandler();
		//$fh->write2Page();
		
		//echo Model_EncryptHelper::sslPassword("jing jiang");
		
		//$dbcb = new Model_DbTable_Apos_Invoicesnewcb(Zend_Registry::get('db_apos'));
		
		//$rows = $dbcb->getInvoicesByDate('2013-05-21');
		
		//var_dump($rows);
		
		/*
		date_default_timezone_set('Australia/Melbourne');
		echo date("Y-m-d H:i:s",1368412200);
		echo date("U",strtotime("2013-04-29"));
		echo "<br />";
		echo date("U",strtotime("2013-05-01"));
		$var = null - null;
		var_dump($var);
		*/
		/*
		$shopHead = new Model_DbTable_Shoplocation();
		$shopHead->setPassword(1,"CC6yja");
		$shopHead->setPassword(2,"WhQTD2");
		$shopHead->setPassword(3,"2RWjHf");
		$shopHead->setPassword(4,"vDD7cJ");
		$shopHead->setPassword(5,"vFd2aL");
		$shopHead->setPassword(6,"XKEbF4");
		$shopHead->setPassword(7,"qLEFB8");
		$shopHead->setPassword(8,"D5txUC");
		$shopHead->setPassword(9,"GkafT2");
		$shopHead->setPassword(10,"7g3JFg");
		$shopHead->setPassword(11,"123456");
		$shopHead->setPassword(12,"MtfMp4");
		$shopHead->setPassword(13,"xeVwC9");
		$shopHead->setPassword(14,"Q6f8jq");
		$shopHead->setPassword(15,"jj9LEp");
		$shopHead->setPassword(16,"NZcnV5");
		$shopHead->setPassword(17,"H5UdWk");
		$shopHead->setPassword(18,"hRnKq8");
		$shopHead->setPassword(19,"nRHaf6");
		$shopHead->setPassword(20,"auEjB2");
		$shopHead->setPassword(22,"h94773");
		$shopHead->setPassword(23,"GaYjG5");
		$shopHead->setPassword(24,"wTdzz7");
		$shopHead->setPassword(25,"FjJYC3");
		$shopHead->setPassword(26,"AKpKc2");
		$shopHead->setPassword(27,"QN72ST");
		$shopHead->setPassword(29,"N7LZY0i");
		*/
		/*
		date_default_timezone_set('Australia/Melbourne');
		
		$ts = new Model_DbTable_Roster_Timesheet();
		$tList = $ts->listAll();
		
		foreach($tList as $key =>$v){


			echo "Begin:".date("Y-m-d H:i",$v["shift_begin"]);
			echo " | End:".date("Y-m-d H:i",$v["shift_end"])."<br />";
			
			
		}
		*/
		
		//$fl = new Model_Fileshandler();
	//$fl->exportExcel();
		
	//echo 	$passwordAfters = Model_EncryptHelper::hashsha("Hereigns7");
	
	//var_dump(strtotime("17:30:00"));
	//var_dump(strtotime("18:00:00"));
		
	//$a =strtotime("17:30:00");
	//$b =strtotime("18:00:00"); 
		//date_default_timezone_set('Australia/Melbourne');
		//$dateToday = Model_DatetimeHelper::dateToday();
	
	//echo date("U",strtotime($dateToday));
	
	//echo date("U",strtotime("2013-04-10"));
	
	//$b = $_GET["d"];
	
	//echo $a = strtotime($b);
	
	//echo "<br />";
	
	
	
	
	
	
		
		/*		
	$ad = new Model_DbTable_Roster_Attnrecord();
	echo $num1 =$ad->createStatusOnDuty();
	echo "<br />";
	echo $ad->getLastOnOffDuty($num1);
	echo "<br />";
	echo $num1 =$ad->createStatusOffDuty();
	echo "<br />";
	echo $ad->getLastOnOffDuty($num1);
	echo "<br />";
	echo $num1 =$ad->createStatusOnDuty();
	echo "<br />";
	echo $ad->getLastOnOffDuty($num1);
	echo "<br />";
	echo $num1 =$ad->createStatusOffDuty();
	echo "<br />";
	echo $ad->getLastOnOffDuty($num1);
	echo "<br />";
	echo $ad->getLastOnOffDuty($num1);
	echo "<br />";
	echo $num1 =$ad->createStatusOnDuty();
	echo "<br />";
	echo $ad->getLastOnOffDuty($num1);
	echo "<br />";
	echo $num1 =$ad->createStatusOffDuty();
	echo "<br />";
	echo $ad->getLastOnOffDuty($num1);
	echo "<br />";
	echo $num1 =$ad->createStatusOnDuty();
	echo "<br />";
	echo $ad->getLastOnOffDuty($num1);
	echo "<br />";
	echo $num1 =$ad->createStatusOffDuty();
	echo "<br />";
	echo $ad->getLastOnOffDuty($num1);
	echo "<br />";			

		date_default_timezone_set('Australia/Melbourne');
		echo $timeNow = time();
		echo "<br />";
		echo date("Y-m-d H:i:s T",$timeNow);
		
		date_default_timezone_set('Australia/Adelaide');
		echo $timeNow = time();
		echo "<br />";
		echo date("r",strtotime("2013-02-01"));	

		$shopHead = new Model_DbTable_Shoplocation();
		
		echo "<br />";
		echo $shopHead->sslPassword("1");
		echo "<br />".strlen($shopHead->sslPassword("1"))."<br />";
		echo $shopHead->sslPassword("a");
		echo "<br />".strlen($shopHead->sslPassword("a"))."<br />";
		echo $shopHead->sslPassword("12s");
		echo "<br />".strlen($shopHead->sslPassword("12s"))."<br />";
		echo $shopHead->sslPassword("Norman Dong");
		echo "<br />".strlen($shopHead->sslPassword("Norman Dong"))."<br />";
		echo $shopHead->sslPassword("12345678901234512345678901234512");
		echo "<br />".strlen($shopHead->sslPassword("12345678901234512345678901234512"))."<br />";
		echo $shopHead->sslPassword("normandong");
		echo "<br />".strlen($shopHead->sslPassword("normandong"))."<br />";
		

		$caClose = new Model_DbTable_Cashaccountclosing();
		
		date_default_timezone_set('Australia/Melbourne');
		$dateToday = date("Y-m-d");
		
		$result = $caClose->getLastBusDayClosing("BSPC", $dateToday);
		$result2 = $caClose->getYesterdayClosing("BSPC");
		
		var_dump($result);
		var_dump($result2);
		
		//echo phpinfo();
	
		$pdf = new Zend_Pdf();
		$page = new Zend_Pdf_Page(Zend_Pdf_page::SIZE_A4);
		
		$pageHeight = $page->getHeight();
		$pageWidth = $page->getWidth();
		
		echo 'Height = '.$pageHeight.'\n';
		echo 'Width = '.$pageWidth.'\n';
		
		
		
		
		$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER),12);
		$page->drawText("Tessafasssssssssssssssssssssssssdt",10,10);
		
		
		
		$pdf->pages[0] = ($page);
		$pdf->save("chomp2.pdf");
		echo $_SERVER['REMOTE_ADDR'];
		
	
		$pwdSource = "CC6yja";
		$iv="thisisnormancode";
		$pass="197979norman";
		$method = 'aes-128-cbc';
		echo $str = openssl_encrypt($pwdSource, $method, $pass,false,$iv);
		echo $pwdResult = openssl_decrypt($str, $method, $pass,false,$iv);
		
		
		
		
		//phpinfo();	
	
		//echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
		
		$browser = get_browser(null, true);
		//echo "<pre>";
		//var_dump($browser);
		//echo "</pre>";
				
		if($browser['platform_description'] =="Windows 7" || $browser['platform_description'] =="Win Xp"){
			
			echo "YES";
		}		
		else{
			echo "NO";
		}

		$caClosing = new Model_DbTable_Cashaccountclosing();
		$cr=$caClosing->getActiveClosingByDate("BSIC","2013-02-13");
		var_dump($cr);
		
		/*
		$shopHead = new Model_DbTable_Shoplocation();
		$shopHead->setToken(1);
		$shopHead->setToken(2);
		$shopHead->setToken(3);
		$shopHead->setToken(4);
		$shopHead->setToken(5);
		$shopHead->setToken(6);
		$shopHead->setToken(7);
		$shopHead->setToken(8);
		$shopHead->setToken(9);
		$shopHead->setToken(10);
		$shopHead->setToken(11);
		$shopHead->setToken(12);
		$shopHead->setToken(13);
		$shopHead->setToken(14);
		$shopHead->setToken(15);
		$shopHead->setToken(16);
		$shopHead->setToken(17);
		$shopHead->setToken(18);
		$shopHead->setToken(19);
		$shopHead->setToken(20);
		//$shopHead->setToken(21);
		$shopHead->setToken(22);
		$shopHead->setToken(23);
		$shopHead->setToken(24);
		$shopHead->setToken(25);
		$shopHead->setToken(26);
		$shopHead->setToken(27);		
			
		$shopHead = new Model_DbTable_Shoplocation();
		$shopHead->setPassword(1,"CC6yja");
		$shopHead->setPassword(2,"WhQTDB");
		$shopHead->setPassword(3,"2RWjHf");
		$shopHead->setPassword(4,"vDD7cJ");
		$shopHead->setPassword(5,"vFd2aL");
		$shopHead->setPassword(6,"XKEbFY");
		$shopHead->setPassword(7,"qLEFBH");
		$shopHead->setPassword(8,"D5txUC");
		$shopHead->setPassword(9,"GkafTV");
		$shopHead->setPassword(10,"7g3JFg");
		$shopHead->setPassword(11,"123456");
		$shopHead->setPassword(12,"MtfMpX");
		$shopHead->setPassword(13,"xeVwCJ");
		$shopHead->setPassword(14,"Q6f8jq");
		$shopHead->setPassword(15,"jj9LEp");
		$shopHead->setPassword(16,"NZcnVu");
		$shopHead->setPassword(17,"H5UdWk");
		$shopHead->setPassword(18,"hRnKqk");
		$shopHead->setPassword(19,"nRHafn");
		$shopHead->setPassword(20,"auEjB2");
		$shopHead->setPassword(22,"h94773");
		$shopHead->setPassword(23,"GaYjGe");
		$shopHead->setPassword(24,"wTdzzp");
		$shopHead->setPassword(25,"FjJYCu");
		$shopHead->setPassword(26,"AKpKcH");
		$shopHead->setPassword(27,"QN72ST");
		N7LZY0i
		$shopHead = new Model_DbTable_Shoplocation();
		$shopHead->setPassword(29,"N7LZY0i");
		$shopHead->setToken(29);
		*/	
	}
	// this is once off function 
	public function zNOUSEonceOffSuperImportAction(){
		
		$fl = fopen('importsuper.csv','r');
		
		$stInfo = new Model_DbTable_Roster_Staffinfo();
		
		
		while(($lineData = fgetcsv($fl,1024))!=false){
			
			$stInfo->updateSuperInfo($lineData[1], $lineData[2], $lineData[7], $lineData[9], $lineData[8], $lineData[5], $lineData[6], $lineData[4], $lineData[10], $lineData[0], $lineData[3]);
		}
		
		
	}

	public function zNOUSEonceAlexOrderAction(){
		$stockmove = new Model_DbTable_Pr_Prstockmovement();
		$loan = new Model_DbTable_Pr_Loan();
		$rJob = new Model_DbTable_Repairjob();
		
		
		if($_POST){
		
			
		$dateBegin = $_POST['date_begin'];
		$dateEnd = $_POST['date_end'];
		$alexOrder = $stockmove->getAlexOrder(31, $dateBegin, $dateEnd,23);
		$alexIn = $loan->AlexIn($dateBegin,$dateEnd);
		$arrAlexOut = $loan->AlexOut($dateBegin, $dateEnd);
		$alexOut = array();
		foreach ($arrAlexOut as $k => $v){

			$rDetail = $rJob->getJob($v['id_job']);
			if($rDetail){
				if($rDetail['repair_staff'] != 380){
					
					$alexOut[] = $v;
				}
			}
		}
		
		$this->view->alexOut = $alexOut;
		$this->view->alexIn = $alexIn;
		$this->view->orderList = $alexOrder;
		}
	}
	
	public function zNOUSEonceOff5HourPolicyAction(){
		//current staff 
		//> 2013 -04-28
		//no duplicate today
		// has attendance record 
		date_default_timezone_set("Australia/Melbourne");
		
		$ts = new Model_DbTable_Roster_Timesheet();
		$stInfo = new Model_DbTable_Roster_Staffinfo();
		$stDetail = new Model_DbTable_Roster_Stafflogindetail();
		$attn = new Model_DbTable_Roster_Attnrecord();
		
		$tList = $ts->listAll();
		$arrRes = array();
		foreach($tList as $k => $v){
			$conShiftBegin = $v['confirm_shift_begin'];
			if($conShiftBegin > 1367071200 && $v['shop_head'] != 'WHPC' && $v['shop_head'] != 'WHCH' && $v['shop_head'] != 'HPPC' && $v['shop_head'] != 'CSIC'  && $v['shop_head'] != 'FGPC'  &&
					($v['confirm_shift_end'] - $v['confirm_shift_begin']) >= 18000 && $v['break_time'] == 0
					){
				
				$idStaff = $v['id_staff'];
				
				$stInfoLine = $stInfo->getStaffinfo($idStaff);
				$sdLine = $stDetail->getDetail($idStaff);
				
				
					//current staff
					if($stInfoLine['old_rate'] < 50 || $stInfoLine['new_rate'] < 50){
						
						//$arrRes[] = $v;
						//by hour staff
						
						$date = date("Y-m-d",$conShiftBegin);
						$arrAtt = $attn->getFirstOnLastOffDuty($idStaff, $date, Model_EncryptHelper::sslPassword($v['shop_head']));
						//d($arrAtt,$idStaff,$date,$v['shop_head']);
						if($arrAtt[0]!="" && $arrAtt[1]!=""){
							
							$arrRes[] = $v;
							
						}	
					}
				
				
			}
		}

		//d($arrRes);
		
		$arrRes2 = array();
		$arrRes3 = array();
		
		foreach($arrRes as $line){
			$arrRes2[$line['shop_head']][$line['id_staff']][] = date("Y-m-d",$line['confirm_shift_begin']);
			$arrRes3[$line['id_staff']][date("Y-m-d",$line['confirm_shift_begin'])] = round(($line['confirm_shift_end'] - $line['confirm_shift_begin'])/3600,2);
		}
		
		d($arrRes2,$arrRes3);
	}
	
	public function zNOUSEonceOffGoodProductsAction(){
		
		// once off function , find products with description, with picture and have enough stock 
		set_time_limit(0);
		$pd = new Model_Products_Detail();
		$pList = $pd->listAll();
		$cot = 0;
		$cot1 = 0;
		foreach($pList as $pLine){
			
			$des = $pLine['description_product'];
			$stock = file_get_contents('http://'.SERVER_IP_COMM.'/products/get-current-stock/barcode/'.trim($pLine['code_product']));
			if(strlen(trim($des)) > 10 && $stock > 10){
				// there is description , check stock 
				// check if the image is there 
				$imgIndiLink = '';
				$imgAllLink = '';
				$imgIndiExist = false;
				$imgAllExist = false;
				
				$fileName1 = trim($pLine['code_product'])."_0.jpg";
				$fileName2 = trim($pLine['code_product'])."_0.JPG";
				
				$fileName3 = trim($pLine['code_product'])."_99.jpg";
				$fileName4 = trim($pLine['code_product'])."_99.JPG";
				
				$positionDash = strrpos(trim($pLine['code_product']),"-");
				$shortBarcode = trim($pLine['code_product']);
				if($positionDash > 0){
					$shortBarcode = substr(trim($pLine['code_product']),0,$positionDash);
				}
				
				$fileName5 = $shortBarcode."-99_0.jpg";
				$fileName6 = $shortBarcode."-99_0.JPG";
				$hfolder = getcwd()."/product_img/home_img/";
				if(file_exists($hfolder.$fileName1)){
					
					$imgIndiExist = true;
					rename($hfolder.$fileName1,getcwd()."/readyfile/".$fileName1);
				}
				if(file_exists($hfolder.$fileName2)){
						
					$imgIndiExist = true;
					rename($hfolder.$fileName2,getcwd()."/readyfile/".$fileName1);
				}
				if(file_exists($hfolder.$fileName3)){
						
					$imgAllExist = true;
					rename($hfolder.$fileName3,getcwd()."/readyfile/".$shortBarcode."_99.jpg");
				}
				if(file_exists($hfolder.$fileName4)){
						
					$imgAllExist = true;
					rename($hfolder.$fileName4,getcwd()."/readyfile/".$shortBarcode."_99.jpg");
				}
				if(file_exists($hfolder.$fileName5)){
				
					$imgAllExist = true;
					rename($hfolder.$fileName5,getcwd()."/readyfile/".$shortBarcode."_99.jpg");
				}
				if(file_exists($hfolder.$fileName6)){
				
					$imgAllExist = true;
					rename($hfolder.$fileName6,getcwd()."/readyfile/".$shortBarcode."_99.jpg");
				}
				
				
				if($imgIndiExist && $imgAllExist){
					$cot++;
				}
				if($imgIndiExist && !$imgAllExist){
					$cot1++;
				}
			}
			
		}
		
		echo $cot."|".$cot1;
		
		
	}
	
	public function zNOUSEonceOffImportFromWebAction(){
		
		//Once Off Function
		//now change to iPHone 6 
		
		set_time_limit(0);
		// once off job
		// run on 126
		$arrRun = array();
		
		$psAtt = new Model_DbTable_Psattribute();
		$psImg = new Model_DbTable_Psproimage();
		$psAttImg = new Model_DbTable_Psattimage();
		$loc = new Model_Products_Location();
		
		
		$proDetail = new Model_Products_Detail();
		
		$pModel = new Model_DbTable_Barcodemodel();
		$pmList = $pModel->listAllModel();
		
		$paList = $psAtt->listAll();
		$color = new Model_DbTable_Barcodecolorcodes();
		
		$cot = 0;
		$arrRes = array();
		
		$fileName = "ebayListing1213_rest.csv";
		$fl = fopen($fileName,"a");
		$web = new Model_Products_Webproduct();
		
		foreach($arrRun as $barcode){
			//get barcode 
			if(trim($barcode)!=''){
			$whStock = file_get_contents('http://'.SERVER_IP_COMM.'/products/get-current-stock/barcode/'.trim($barcode));
			$idWeb = $web->fetchWebId($barcode,"ebay","k-mobile");
			
			if($whStock > 10 && !$idWeb){
				$cot ++;
				$tmpArr = array();
				$tmpArr[] = 'NO'; // new products
				$tmpArr[] = trim($barcode); // barcode
				$tmpArr[] = '';//chinese title
				$aposTitle = file_get_contents('http://'.SERVER_IP_COMM.'/products/get-old-apos-product-description/barcode/'.trim($barcode));
				$tmpArr[] = $aposTitle;//apos title
				$tmpArr[] = Model_DatetimeHelper::dateToday();//first date
				$tmpArr[] = '';//inital stock empty
				$brand = '';
				Switch(substr($barcode,0,2)){
					case('AP'):{$brand = 'Apple';break;}
					case('HT'):{
						$brand = 'HTC';break;
					}
					case('SA'):{
						$brand = 'Samsung';break;
					}
					case('NO'):{
						$brand = 'Nokia';break;
					}
					case('UI'):{
						$brand = 'Universal';break;
					}
					case('LG'):{
						$brand = 'LG';break;
					}
					case('SE'):{
						$brand = 'Sony';break;
					}
					
				}
				
				$tmpArr[] = $brand;//brand empty
				$model = '';
				foreach($pmList as $k => $v){
					if(trim($v['code_model'])!=""){
					if(strpos($barcode,$v['code_model'])!==false){
						
					$model = $v['des_model'];	
					break;	
					}
					}
					
				}
				
				
				
				$tmpArr[] = $model;//model
				$tmpArr[] = '';//MUST FILL
				$tmpArr[] = $aposTitle;//MUST MODIFY put apos title put modify
				$tmpArr[] = '';//empty webite short des
				$pDes = $proDetail->getDetailByCode($barcode);
				
				$tmpArr[] = $pDes['description_product'];// ebay des
				
				$tmpArr[] = '';//feature
				$tmpArr[] = '';//size
				$tmpArr[] = '';//weight
				$tmpArr[] = '';//warranty
				
				$positionDash = strrpos($barcode,"-");
				$shortBarcode = trim($barcode);
				if($positionDash > 0){
					$shortBarcode = substr($barcode,0,$positionDash);
				}
				$idColor = str_replace("-","",substr($barcode,$positionDash));
				
				$tmpArr[] = $shortBarcode."_99.jpg";//full color 
				$tmpArr[] = trim($barcode)."_0.jpg";//individual color 
				$tmpArr[] = '';//zippic empty
				$tmpArr[] = '';//supplyer name empty
				$tmpArr[] = '';//supplier barcode empty
				$tmpArr[] = '';//postage **
				
				$colorDes = $color->getColorDes($idColor);
				$tmpArr[] = $colorDes;//color if I can calculate 
				
				$tmpArr[] = '';//ebay price
				$tmpArr[] = '';//lovebargain price
				$tmpArr[] = '';//phone col price 
				$tmpArr[] = '';//location put to empty
				$tmpArr[] = 20349;//
				$locList = $loc->getLocationsByProduct($barcode);
				$strLoc = '';
				if(!empty($locList)){
				foreach($locList as $k => $v){
					$strLoc .=$v['code_location'].",";
					
				}
				}
				$tmpArr[] = $strLoc;
				$tmpArr[] = trim(file_get_contents('http://'.SERVER_IP_COMM.'/products/get-old-apos-product-pricea/barcode/'.trim($barcode)));
				
				
				
				/*
				 *  Download picture part is done now create the csv file 
				 *  
				$idAtt = $paLine['id_product_attribute'];
				
				$idImgLine = $psAttImg->getPsattimage($idAtt);
				
				$strFolder = implode("/",str_split((string)$idImgLine['id_image']));
				
				echo $url = "http://www.phonecollection.com.au/shopping/img/p/".$strFolder."/".(string)$idImgLine['id_image']."-thickbox_default.jpg";
				//http://www.phonecollection.com.au/shopping/img/p/6/4/0/6/6406-thickbox.jpg
				echo "<br />";
				
				$folder = getcwd()."/inddownload/";
				
				$result = Model_System_Downloadhelper::downloadUrl($url);
					
				$fl = fopen($folder.trim($paLine['reference'])."_0.jpg","w");
				fputs($fl,$result);
				fclose($fl);
				
				//download Individual imags
				
				$idProduct = $paLine['id_product'];
				
				$idProImg = $psImg->getProductCover($idProduct);
				
				$strFolder2 = implode("/",str_split((string)$idProImg));
				$url2 = "http://www.phonecollection.com.au/shopping/img/p/".$strFolder."/".(string)$idProImg."-thickbox_default.jpg";
				
				$folder2 = getcwd()."/alldownload/";
				
				$result2 = Model_System_Downloadhelper::downloadUrl($url2);
				
				$positionDash = strrpos(trim($paLine['reference']),"-");
				$shortBarcode = trim($paLine['reference']);
				if($positionDash > 0){
					$shortBarcode = substr(trim($paLine['reference']),0,$positionDash);
				}
				
				$fl2 = fopen($folder2.$shortBarcode."_99.jpg","w");
				fputs($fl2,$result2);
				fclose($fl2);
			
				*/
				
				$arrRes[] = $tmpArr;
				fputcsv($fl, $tmpArr);
			}
			}
			
		}
		
		fclose($fl);
		echo $cot;
		d($arrRes);
		
	}
	
	public function zNOUSEtimeCheckAction(){
		$attRecord = new Model_DbTable_Roster_Attnrecord();
		$sDetail = new Model_DbTable_Roster_Stafflogindetail();
		date_default_timezone_set("Australia/Melbourne");
		$dateToday = Model_DatetimeHelper::dateToday();
		$arrStart = $dateToday." 09:15";
		$arrMax = $dateToday." 09:16";
		$random = rand(1,60);
		$fixTime = $dateToday."09:14:".$random;
		if(isset($_POST['submit'])){
			$password = $_POST['password'];
			if(!empty($password)){
				$idStaffRow = $sDetail->checkPasswordCorrect(Model_EncryptHelper::hashsha(trim($password)));
		
				$intStart = Model_DatetimeHelper::tranferToInt($arrStart);
				$intMax = Model_DatetimeHelper::tranferToInt($arrMax);
				$intFix = Model_DatetimeHelper::tranferToInt($fixTime);

				if($idStaffRow){
					$timeSheet = $attRecord->listRecordByStaffId($idStaffRow['id'], $dateToday, $dateToday);
					d($timeSheet);
					if($timeSheet[0]['ti']> $intStart && $timeSheet < $intMax){
						$this->view->time = date('Y-m-d H:i:s',$timeSheet[0]['ti']);
						$this->view->fixTime = date('Y-m-d H:i:s',$intFix);
					}else{
						$this->view->message = "Not in 9:15-9:16 period, No need change";
						$this->view->time = date('Y-m-d H:i:s',$timeSheet[0]['ti']);
						$this->view->fixTime = date('Y-m-d H:i:s',$intFix);
					}
				
				}else{
					echo "Wrong Password";
				}
			}
			
		}
		
	}
	
	public function zNOUSEonceOffPrBackorderAction(){
		// check 11/12
		$dateBo  = "2014-11-24";
		$bo = new Model_DbTable_Pr_Backorder();
		$boList = $bo->getBoByDate($dateBo);
		$od = new Model_DbTable_Pr_Order();
	
		//d($boList);
	
		foreach($boList as $k => $v){
			$idShop = $v['id_shop'];
			$code = $v['code_product'];
			$odLine = $od->getOrderByShopByDateByCode($idShop,'2014-12-01', $code);
				
			if(( $odLine['qty_allocate'] >= $odLine['qty_backorder'])  ){
				echo "Partal";
				d($odLine);
				$bo->fullfillBackOrder($v['id_bo'],'2014-12-05');
			}
				
		}
	
	
	}
	
	public function zNOUSEonceOffImportPriceAction(){
		
		$fileName = "price.csv";
		
		$fprice = new Model_DbTable_Products_Price_Flexprice();
		$fHistory = new Model_DbTable_Products_Price_Flexpricehistory();
		$pro = new Model_DbTable_Productsva();
		$pDetail = new Model_Products_Detail();
		
		$fl = fopen(getcwd()."/".$fileName,"r");
		while(($lineData = fgetcsv($fl,1024))!=false){
						
			$idPro = $pro->getProductID(trim($lineData[0]));
			$fprice->updateFlexprice($idPro,3, $lineData[1],Model_DatetimeHelper::dateToday());
			$pDetail->lastUpdate(trim($lineData[0]));
			//$fHistory->addHistory($idPro,3,Model_DatetimeHelper::dateToday(), $lineData[1]);
		}
		
		
	}
	/**
	 * it check how long the kt can hold
	 */
	public function ktHoldAction(){
		//this run on 126
	
		$ktNo = $this->_getParam("kt_no");
		$shop = $this->_getParam("shop");
		$aKt = Model_Aposinitnew::initKtData($shop);
		$arrShop = unserialize(ARR_APOS_NEW_SHOP_MAPPING);
		$kList = $aKt->listKT($ktNo,$arrShop[$shop]);
		d($kList);
	}

}
?>